package com.mandao.oneplat.boot.context;

import com.mandao.oneplat.boot.util.CollectionUtil;
import io.netty.handler.codec.http.DefaultHttpResponse;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.codec.http.cookie.Cookie;

import java.util.ArrayList;
import java.util.List;

import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST;
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;

/**
 * Created by sunson on 2017/3/23.
 */
public class OneResponse {

    public static HttpResponse BAD_RESPONSE = new DefaultHttpResponse(HTTP_1_1, BAD_REQUEST);

    private HttpResponse httpResponse;
    private List<Cookie> cookies;

    public OneResponse() {
    }

    public OneResponse(HttpResponse httpResponse) {
        this.httpResponse = httpResponse;
    }

    public HttpResponse getHttpResponse() {
        return httpResponse;
    }

    public void setHttpResponse(HttpResponse httpResponse) {
        this.httpResponse = httpResponse;
    }

    public List<Cookie> getCookies() {
        return cookies;
    }

    public void setCookies(List<Cookie> cookies) {
        this.cookies = cookies;
    }

    public void addCookie(Cookie cookie) {
        if (CollectionUtil.isEmpty(cookies)) {
            cookies = new ArrayList<>();
        }
        cookies.add(cookie);
    }

}
